//2009/09/04 15:44:20
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class CrossCountry
{
public:
    string scoreMeet(int numTeams, string finishOrder)
    {
        vector<pair<pair<int, int>, pair<char, int> > > v (numTeams);
        //v.clear();
        //score, sixth's score, teamName, numberOfplayers;
        for (int i=0; i<finishOrder.size(); i++)
        {
			v[finishOrder[i] - 'A'].second.second ++;
            if (v[finishOrder[i] - 'A'].second.second < 6)
			{
                v[finishOrder[i] - 'A'].first.first += i+1;
				v[finishOrder[i] - 'A'].first.second = 100000;
			}
            if (v[finishOrder[i] - 'A'].second.second == 6)
                v[finishOrder[i] - 'A'].first.second = i+1;
            v[finishOrder[i] - 'A'].second.first = finishOrder[i];
        }
        sort(v.begin(), v.end());
        for (int i=0; i<v.size(); i++)
            cout << v[i].second.first << ": " << v[i].first.first << ", " << v[i].second.second << endl;
        string s;
        for (int i=0; i<v.size(); i++)
            if (v[i].first.first >0 && v[i].second.second >4)
                s += v[i].second.first;
        return s;
    }
};
